import { describe, expect, test } from '@jest/globals';
import { copySync, removeSync } from 'fs-extra';
import { resolve } from 'path';

import { initByStageEmptyApp, initExecuteCommand, runHvigor } from './common/common';
import { ModuleJsonModifier } from './common/modifier/module-json-modifier';

describe('Multi project', () => {
  test.concurrent('entry with js feature', async () => {

    // 删除entry里的js, 并复制到feature, 使feature存在entry没有的js语言类型
    await initByStageEmptyApp(async (project) => {
      copySync(resolve(project, 'entry', 'src', 'main', 'js'), resolve(project, 'feature', 'src', 'main', 'js'));
      removeSync(resolve(project, 'entry', 'src', 'main', 'js'));
      removeSync(resolve(project, 'entry', 'src', 'main', 'ets', 'FormAbility'));
      const moduleJsonModifier: ModuleJsonModifier = new ModuleJsonModifier(project, 'entry');
      moduleJsonModifier.setExtensionAbilities(undefined);
      moduleJsonModifier.outputSync();
      const commands = initExecuteCommand({
        mode: 'module',
        product: 'default',
        tasks: 'assembleHap'
      });
      const result = runHvigor(project, commands);
      expect(result.stdout.includes('BUILD SUCCESSFUL')).toBeTruthy();
    });
  });
});
